<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  函数式编程 --- AOP 面向切面编程

  <script>
    Function.prototype.before = function(beforeFn) {
      let _this = this
      // console.log(this);
      return function() {
        beforeFn();
        _this();
      }
    }

    Function.prototype.after = function(afterFn) {
      let _this = this
      return function() {
        _this();
        afterFn()
      }
    }


    function test() {
      console.log(2);
    }

    test = test
      .before(function() {
        console.log(1);
      })
      .after(function() {
        console.log(3);
      })

    test();
  </script>

</body>

</html>